import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

/* Layout */
// const Layout = resolve => require(['@/views/layout/Layout'], resolve);

/* Router Modules */
import Activity from './modules/Activity';
import ApplicationGoods from './modules/applicationGoods';
import Customer from './modules/Customer';
import Default from './modules/Default';
import Exam from './modules/Exam';
import Finance from './modules/Finance';
import FormalCustomer from './modules/FormalCustomer';
import FormManage from './modules/formManage';
import Information from './modules/Information';
import Member from './modules/Member';
import Order from './modules/Order';
import Permission from './modules/Permission';
import Plugin from './modules/Plugin';
import Product from './modules/Product';
import Questionnaire from './modules/Questionnaire';
import Setting from './modules/Setting';
import Staff from './modules/Staff';
import TencentCloud from './modules/TencentCloud';
import Wallet from './modules/Wallet';
import WeChatApp from './modules/WeChatApp';
import Workbench from './modules/Workbench';
import WorkOrder from './modules/WorkOrder';
import SuperWorkOrder from './modules/SuperWorkOrder';
import VideoBlogger from './modules/VideoBlogger';

import Error from './modules/Error';

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
/* default routers */
export const constantRouterMap = [
  { path: '/login', component: resolve => require(['@/views/login/index'], resolve), hidden: true }
];

/* modules routers */
export const asyncRouterMap = [
  Workbench,
  Information,
  Product,
  Customer,
  FormalCustomer,
  Order,
  Plugin,
  Wallet,
  Finance,
  Staff,
  WorkOrder,
  SuperWorkOrder,
  TencentCloud,
  Activity,
  Member,
  Exam,
  Questionnaire,
  ApplicationGoods,
  VideoBlogger,
  FormManage,
  Permission,
  WeChatApp,
  Setting
];

export const errorRouterMap = Error;
export const defaultRouterMap = Default;

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
});

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
